package com.jsb.laundry.common.mq;

import com.jsb.laundry.common.constant.CommonConstants;
import org.springframework.amqp.core.Binding;
import org.springframework.amqp.core.BindingBuilder;
import org.springframework.amqp.core.CustomExchange;
import org.springframework.amqp.core.Queue;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;

import java.util.HashMap;
import java.util.Map;

/**
 * 30分钟待支付队列配置
 */
@Configuration
public class WaitPayConfig {

    //交换机名
    public static final String ORDER_30_CANCEL_EXCHANGE = "wait_pay_30_exchange";

    //队列名
    public static final String ORDER_30_CANCEL_QUEUE = "wait_pay_30_queue";

    //routingKey
    public static final String ORDER_30_CANCEL_ROUTING_KEY = "wait_pay_30_routing_key";

    /**
     *  声明队列
     */
    @Bean
    public Queue waitPayQueue() {
        return new Queue(ORDER_30_CANCEL_QUEUE);
    }

    /**
     * 声明自定义交换机
     */
    @Bean
    public CustomExchange waitPayExchange() {
        Map<String, Object> arguments = new HashMap<>();
        arguments.put("x-delayed-type", "direct");
        return new CustomExchange(ORDER_30_CANCEL_EXCHANGE, "x-delayed-message",
                true, false, arguments);
    }

    /**
     *  队列绑定交换机
     */
    @Bean
    public Binding waitPayQueueBindingWaitPayExchange(Queue waitPayQueue,
                                                      CustomExchange waitPayExchange) {
        return BindingBuilder.bind(waitPayQueue).to(waitPayExchange)
                .with(ORDER_30_CANCEL_ROUTING_KEY).noargs();
    }


}
